<template>
  <div class="home-container">
     <!-- 登录导航 -->
     <!-- 这是顶部导航的固定定位 -->
   <van-nav-bar class="page-nav-bar" fixed>
     <van-button
       class="search-btn"
        slot="title"
        type="info"
        size="small"
        round
        icon="search"
     >搜索</van-button>
    </van-nav-bar>
    <!-- 标签页 列表 -->
    <van-tabs class="channel-tabs" v-model="active" animated swipeable  swipe-threshold="3" >
      <van-tab
      v-for="(obj,ind) in channels"
      :key="ind"
      :title="obj.name"
      >
     <!-- 导入组件 -->
     <ArticleList :channel= "obj"> </ArticleList>
      </van-tab>
      <!-- 占位的防止最后一个被遮挡 -->
      <div slot="nav-right" class="placeholder"></div>
      <!-- 憨包按钮 -->
      <div slot="nav-right"
           class="hamburger-btn"
           @click="isChennelEditShow = true">
        <i class="toutiao toutiao-gengduo"></i>
        </div>
    </van-tabs>
    <!-- 弹出层 -->
    <van-popup
      v-model="isChennelEditShow"
      closeable
      close-icon-position="top-left"
      position="bottom"
      :style="{ height: '100%' }"
    >
    <!-- 频道编辑组件 -->
    <ChannelEdit
      :myChannels="channels"
      :myActive= "active"
      @update-active='updateActive'
    ></ChannelEdit>
     <!-- 频道编辑组件 -->
    </van-popup>
  </div>
</template>

<script>
// .导入 获取用户列表的方法
import { getUserChannelsAPI } from '../../api/index.js'
// 导入组件
import ArticleList from './components/article-list.vue'
import ChannelEdit from './components/channel-edit.vue'
export default {
  name: 'HomePage',
  components: {
    ArticleList, ChannelEdit
  },
  props: {
  },
  data () {
    return {
      active: 0,
      channels: [], // 频道列表
      isChennelEditShow: false // 控制编辑频道页面是否显示
    }
  },
  computed: {},
  watch: {},
  created () {
    this.loadChannels()
  },
  mounted () {},
  methods: {
    // 获取频道列表
    async loadChannels () {
      try {
        const { data } = await getUserChannelsAPI()
        this.channels = data.data.channels
        // console.log(this.channels)
      } catch (err) {
        this.$toast('获取频道列表数据失败')
      }
    },
    // 子组件穿了一个修改active
    updateActive (index, state) {
      this.active = index
      // 关闭编辑页面
      this.isChennelEditShow = state
    }
  }
}
</script>

<style  lang="less" scoped>
.home-container{
  // 让内容区域不被上下的定位所遮挡
  padding-top: 174px;
  padding-bottom: 100px;
  //设置顶部导航栏内容
  /deep/.van-nav-bar__title{
    max-width: unset;
  }
  //顶部导航搜索框样式
    .search-btn{
    width: 555px;
    height: 64px;
    background-color: #5babfb;
    border: none;
    font-size: 28px;
    .van-icon {
      font-size: 32px;
    }
  }
  //标签导航样式设置
 :deep(.channel-tabs){
      .van-tabs__wrap {
        // 这是频道列表的固定定位
        position: fixed;
        top: 92px;
        z-index: 1;
        left: 0;
        right: 0;
        height: 82px;
      }
    .van-tab{
      min-width: 200px;
      font-size: 30px;
      color: #777777;
      border-right: 1px solid #edeff3;
    }
    .van-tab--active{
      color: #333333;
    }
   .van-tabs__nav {
    padding-bottom: 0;
  }
   .van-tabs__line {
    bottom: 8px;
    width: 31px !important;
    height: 6px;
    background-color: #3296fa;
  }
  //占位符设置
   /deep/ .placeholder {
    flex-shrink: 0; /* flex布局需要用这个属性不让它参与flex计算 */
    width: 66px;
    height: 82px;
  }
  //憨包按钮设置
    .hamburger-btn {
      position: fixed;
      right: 0;
      height: 88px;
      width: 66px;
      display: flex;
      justify-content: center;
      align-items: center;
      background-color: #fff;

      // 通过伪类选择器来设置汉堡标签最左侧的竖线
      &::before {
        content: '';
        position: absolute;
        left: 0;
        background-image: url(../../assets/gradient-gray-line.png);
        background-size: contain;
        width: 2px;
        height: 58px;
      }
    }
  }
}
</style>
